package com.example.user.event;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 有序事件监听器
 * 可通过@Order指定顺序
 *
 * @Async 异步执行，此时无序
 * @author vanson
 */
@Slf4j
@Component
@Order(1)
public class KeyLogEventListener implements ApplicationListener<KeyLogEvent> {

    @Async("logPool")
    @Override
    public void onApplicationEvent(KeyLogEvent keyLogEvent) {
        log.info("关键操作日志：{}", keyLogEvent.getUser().toString());
    }
}
